package br.xraylol;

import java.io.File;

import org.apache.commons.io.monitor.FileAlterationMonitor;
import org.apache.commons.io.monitor.FileAlterationObserver;

/**
 * 
 * @author John Yeary
 * @version 1.0
 */
public class FileMonitor {

	public void createListener() {
		try {
			final File directory = new File("G:\\lolPrint");
			FileAlterationObserver fao = new FileAlterationObserver(directory);
			fao.addListener(new FileAlterationExecute());
			final FileAlterationMonitor monitor = new FileAlterationMonitor();
			monitor.addObserver(fao);
			monitor.start();

			Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

				@Override
				public void run() {
					try {
						monitor.stop();
					} catch (Exception ignored) {
					}
				}
			}));

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}